package com.opages.mvc.adapter.common.utils;

import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author daizhong.liu
 * @create 2020-07-02 11:06
 **/
public class IPUtils {
    public static String fixIPv6Address(String address) {
        try {
            InetAddress inetAdr = InetAddress.getByName(address);
            if (inetAdr instanceof Inet6Address) {
                return "[" + inetAdr.getHostName() + "]";
            }
            return address;
        }
        catch (UnknownHostException e) {
            e.printStackTrace();
            return address;
        }
    }
}
